package org.htmlparser.lexer;

import org.htmlparser.Attribute;

public class PageAttribute extends Attribute
{
  protected int mNameEnd;
  protected int mNameStart;
  protected Page mPage;
  protected int mValueEnd;
  protected int mValueStart;

  public PageAttribute()
  {
    init();
  }

  public PageAttribute(String paramString)
    throws IllegalArgumentException
  {
    super(paramString);
    init();
  }

  public PageAttribute(String paramString1, String paramString2)
  {
    super(paramString1, paramString2);
    init();
  }

  public PageAttribute(String paramString1, String paramString2, char paramChar)
  {
    super(paramString1, paramString2, paramChar);
    init();
  }

  public PageAttribute(String paramString1, String paramString2, String paramString3)
  {
    super(paramString1, paramString2, paramString3);
    init();
  }

  public PageAttribute(String paramString1, String paramString2, String paramString3, char paramChar)
  {
    super(paramString1, paramString2, paramString3, paramChar);
    init();
  }

  public PageAttribute(Page paramPage, int paramInt1, int paramInt2, int paramInt3, int paramInt4, char paramChar)
  {
    this.mPage = paramPage;
    this.mNameStart = paramInt1;
    this.mNameEnd = paramInt2;
    this.mValueStart = paramInt3;
    this.mValueEnd = paramInt4;
    super.setName(null);
    super.setAssignment(null);
    super.setValue(null);
    super.setQuote(paramChar);
  }

  private void init()
  {
    this.mPage = null;
    this.mNameStart = -1;
    this.mNameEnd = -1;
    this.mValueStart = -1;
    this.mValueEnd = -1;
  }

  public String getAssignment()
  {
    String str = super.getAssignment();
    if ((str == null) && (this.mPage != null) && (this.mNameEnd >= 0) && (this.mValueStart >= 0))
    {
      str = this.mPage.getText(this.mNameEnd, this.mValueStart);
      if ((str.endsWith("\"")) || (str.endsWith("'")))
        str = str.substring(0, str.length() - 1);
      super.setAssignment(str);
    }
    return str;
  }

  public void getAssignment(StringBuffer paramStringBuffer)
  {
    String str = super.getAssignment();
    if (str == null)
      if ((this.mPage != null) && (this.mNameEnd >= 0) && (this.mValueStart >= 0))
      {
        this.mPage.getText(paramStringBuffer, this.mNameEnd, this.mValueStart);
        int i = paramStringBuffer.length() - 1;
        int j = paramStringBuffer.charAt(i);
        if ((39 == j) || (34 == j))
          paramStringBuffer.setLength(i);
      }
    while (true)
    {
      return;
      paramStringBuffer.append(str);
    }
  }

  public int getLength()
  {
    int i = 0;
    String str1 = super.getName();
    if (str1 != null)
    {
      i = 0 + str1.length();
      String str2 = super.getAssignment();
      if (str2 == null)
        break label101;
      i += str2.length();
      String str3 = super.getValue();
      if (str3 == null)
        break label137;
      i += str3.length();
    }
    while (true)
    {
      label137: 
      do
        while (true)
        {
          label101: 
          do
            while (true)
            {
              do
              {
                if (super.getQuote() != 0)
                  i += 2;
                return i;
              }
              while ((this.mPage == null) || (this.mNameStart < 0) || (this.mNameEnd < 0));
              i = 0 + this.mNameEnd - this.mNameStart;
            }
          while ((this.mPage == null) || (this.mNameEnd < 0) || (this.mValueStart < 0));
          i += this.mValueStart - this.mNameEnd;
        }
      while ((this.mPage == null) || (this.mValueStart < 0) || (this.mValueEnd < 0));
      i += this.mValueEnd - this.mValueStart;
    }
  }

  public String getName()
  {
    String str = super.getName();
    if ((str == null) && (this.mPage != null) && (this.mNameStart >= 0))
    {
      str = this.mPage.getText(this.mNameStart, this.mNameEnd);
      super.setName(str);
    }
    return str;
  }

  public void getName(StringBuffer paramStringBuffer)
  {
    String str = super.getName();
    if (str == null)
      if ((this.mPage != null) && (this.mNameStart >= 0))
        this.mPage.getText(paramStringBuffer, this.mNameStart, this.mNameEnd);
    while (true)
    {
      return;
      paramStringBuffer.append(str);
    }
  }

  public int getNameEndPosition()
  {
    return this.mNameEnd;
  }

  public int getNameStartPosition()
  {
    return this.mNameStart;
  }

  public Page getPage()
  {
    return this.mPage;
  }

  public String getRawValue()
  {
    String str = getValue();
    if (str != null)
    {
      char c = super.getQuote();
      if (c != 0)
      {
        StringBuffer localStringBuffer = new StringBuffer(2 + str.length());
        localStringBuffer.append(c);
        localStringBuffer.append(str);
        localStringBuffer.append(c);
        str = localStringBuffer.toString();
      }
    }
    return str;
  }

  public void getRawValue(StringBuffer paramStringBuffer)
  {
    if (this.mValue == null)
      if (this.mValueEnd >= 0)
      {
        char c2 = super.getQuote();
        if (c2 != 0)
          paramStringBuffer.append(c2);
        if (this.mValueStart != this.mValueEnd)
          this.mPage.getText(paramStringBuffer, this.mValueStart, this.mValueEnd);
        if (c2 != 0)
          paramStringBuffer.append(c2);
      }
    while (true)
    {
      char c1;
      do
      {
        return;
        c1 = super.getQuote();
        if (c1 != 0)
          paramStringBuffer.append(c1);
        paramStringBuffer.append(this.mValue);
      }
      while (c1 == 0);
      paramStringBuffer.append(c1);
    }
  }

  public String getValue()
  {
    String str = super.getValue();
    if ((str == null) && (this.mPage != null) && (this.mValueEnd >= 0))
    {
      str = this.mPage.getText(this.mValueStart, this.mValueEnd);
      super.setValue(str);
    }
    return str;
  }

  public void getValue(StringBuffer paramStringBuffer)
  {
    String str = super.getValue();
    if (str == null)
      if ((this.mPage != null) && (this.mValueEnd >= 0))
        this.mPage.getText(paramStringBuffer, this.mNameStart, this.mNameEnd);
    while (true)
    {
      return;
      paramStringBuffer.append(str);
    }
  }

  public int getValueEndPosition()
  {
    return this.mValueEnd;
  }

  public int getValueStartPosition()
  {
    return this.mValueStart;
  }

  public boolean isEmpty()
  {
    int i;
    if ((!(isWhitespace())) && (!(isStandAlone())) && (super.getValue() == null) && (((this.mPage == null) || ((this.mPage != null) && (this.mValueEnd < 0)))))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isStandAlone()
  {
    int i;
    if ((!(isWhitespace())) && (super.getAssignment() == null) && (!(isValued())) && (((this.mPage == null) || ((this.mPage != null) && (this.mNameEnd >= 0) && (this.mValueStart < 0)))))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isValued()
  {
    int i;
    if ((super.getValue() != null) || ((this.mPage != null) && (this.mValueStart >= 0) && (this.mValueEnd >= 0) && (this.mValueStart != this.mValueEnd)))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isWhitespace()
  {
    int i;
    if (((super.getName() == null) && (this.mPage == null)) || ((this.mPage != null) && (this.mNameStart < 0)))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public void setNameEndPosition(int paramInt)
  {
    this.mNameEnd = paramInt;
    super.setName(null);
    super.setAssignment(null);
  }

  public void setNameStartPosition(int paramInt)
  {
    this.mNameStart = paramInt;
    super.setName(null);
  }

  public void setPage(Page paramPage)
  {
    this.mPage = paramPage;
  }

  public void setValueEndPosition(int paramInt)
  {
    this.mValueEnd = paramInt;
    super.setValue(null);
  }

  public void setValueStartPosition(int paramInt)
  {
    this.mValueStart = paramInt;
    super.setAssignment(null);
    super.setValue(null);
  }
}